﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BalanceCenter_CommendList : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        isAtFramePageLogin = true;                              //是框架页
        RequestLoginPage = this.Request.Url.AbsoluteUri;
        RequestCompetences = Competences.BuildCompetencesList(Competences.Net);

        base.OnInit(e);
    }

    #endregion

    private void BindData()
    {
        DataTable dt = new DAL.Views.V_Customer().Open("", "isActivation = 1 and CommendID = " + _Customer.ID.ToString(), "[RegisterDate]");

        g.DataSource = dt;
        g.DataBind();
        gPager.Visible = (dt.Rows.Count > 0);
    }

    protected void g_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            e.Item.Cells[12].Text = Shove._Convert.StrToDateTime(e.Item.Cells[11].Text, System.DateTime.Now.ToString()).ToShortDateString();
        }
    }

    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        BindData();
    }

    protected void gPager_SortBefore(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
    {
        BindData();
    }

    protected void btnSerchAll_Click(object sender, EventArgs e)
    {
        BindData();
    }

    protected void btnSerch_Click(object sender, EventArgs e)
    {
        if (this.tbSerch.Text.Trim().Equals(""))
        {
            Shove._Web.JavaScript.Alert(this, "请输入要搜索的会员ID");

            return;
        }

        Customer customer = new Customer(_Site.ID);
        customer.CustomerNO = this.tbSerch.Text.Trim();
        string Return = "";

        int Result = customer.GetCustomerInformationByNO(ref Return);

        if (Result == -1)
        {
            Shove._Web.JavaScript.Alert(this, "此会员不存在");
            return;
        }

        DataTable dt = null;

        if (_Customer.Competences[Competences.Administrator])
        {
            dt = new DAL.Views.V_Customer().Open("", "[ID] = " + customer.ID.ToString(), "");
        }
        else
        {
            dt = new DAL.Views.V_Customer().Open("", "[CommendID] = " + _Customer.ID + "and [ID] = " + customer.ID.ToString(), "");
        }

        gPager.PageIndex = 0;

        g.DataSource = dt;
        g.DataBind();
        gPager.Visible = (dt.Rows.Count > 0);
    }

    protected void g_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            long ID = Shove._Convert.StrToLong(e.Item.Cells[14].Text, -1);
          //  string ReturnDescription = "";

            if (e.CommandName == "Del")
            {
                //if (DAL.Procedures.P_DelUser(ID, ref ReturnDescription) < 0)
                //{
                //    Shove._Web.JavaScript.Alert(this.Page, ReturnDescription);

                //    return;
                //}

                Shove._Web.JavaScript.Alert(this.Page, "删除成功");
            }

            BindData();
        }
    }
}
